﻿public class Solution
{
    private IList<IList<int>> result = new List<IList<int>>();
    private IList<int> path = new List<int>();
    
    public IList<IList<int>> Subsets(int[] nums)
    {
        trackbacking(nums, 0);
        return result;
    }

    private void trackbacking(int[] nums, int start)
    {
        result.Add(new List<int>(path));
        if (start >= nums.Length) return;
        for (int i = start; i < nums.Length; i++)
        {
            path.Add(nums[i]);
            trackbacking(nums, i+1);
            path.RemoveAt(path.Count-1);
        }
    }

    public static void Main(string[] args)
    {
        int[] nums = [1, 2, 3];

        Solution solution = new Solution();
        IList<IList<int>> resu = solution.Subsets(nums);

        foreach (IList<int> res in resu)
        {
            foreach (int r in res)
            {
                Console.Write($"{r} ");
            }
            Console.WriteLine();
        }
    }
}